package com.iwork.jute;

import lombok.Data;

import java.io.Serializable;

@Data
public class Response<T> implements Serializable {
    private static final long serialVersionUID = 6138979130005367537L;
    private boolean status;
    private T data;
    private String errMsg;

    public Response() {
    }

    public void setResult(T result) {
        this.status = true;
        this.data = result;
    }

    public void setErrMsg(String errMsg) {
        this.status = false;
        this.errMsg = errMsg;
    }

    public static <T> Response<T> ok(T data) {
        Response resp = new Response();
        resp.setResult(data);
        return resp;
    }

    public static <T> Response<T> ok() {
        return (Response<T>) ok((Object)null);
    }

    public static <T> Response<T> fail(String error) {
        Response resp = new Response();
        resp.setErrMsg(error);
        return resp;
    }

}
